import React, {Component} from 'react';
import {WebView} from 'react-native-webview';

export default class MyWeb extends Component {
  render() {
    const run = `
      document.body.style.backgroundColor = 'blue';
      true;
    `;
    setTimeout(() => {
      this.webref.injectJavaScript(run);
    }, 2000);
    const html = `
      <html>
      <head></head>
      <body>
        <script>
          setTimeout(function () {
            window.ReactNativeWebView.postMessage("Hello!")
            window.alert(document.documentElement.innerHTML)
          }, 1000)
        </script>
      </body>
      </html>
    `;
    return (
      <WebView
        ref={r => (this.webref = r)}
        source={{html}}
        onMessage={event => {
          alert(event.nativeEvent.data);
        }}
      />
    );
  }
}
